<template>
  <div class="ke-course-teacher-info">
    <div class="teacher-info">
      <div class="avatar">
        <img :src="avatar" />
      </div>
      <div class="name">{{teacherInfo.nickName}}</div>
      <div class="personalized">{{teacherInfo.personalized}}</div>
    </div>
    <div class="course-desc">
      <div class="title">课程介绍</div>
      <div class="desc">{{courseSrc.description}}</div>
    </div>
    <div class="comment">
      <el-input type="textarea" placeholder="请输入内容" v-model="comment" resize="none" />
      <el-input-number
        v-model="score"
        :precision="1"
        :step="0.1"
        :max="5"
        :min="0"
        style="width: 100%; margin-top: 5px;"
      />
      <el-button type="primary" style="width: 100%; margin-top: 5px;" @click="handleComent">完成评论</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'keCourseTeacherInfo',
  inject: ['reload'],
  data() {
    return {
      courseSrc: {},
      teacherInfo: {},
      comment: '',
      score: 0
    }
  },
  computed: {
    avatar() {
      if (this.teacherInfo.avatar !== undefined) {
        return this.teacherInfo.avatar
      } else {
        return require('../../assets/images/node.jpg')
      }
    }
  },
  mounted() {
    this.getCourseSrc()
    this.getTeacherInfo()
  },
  methods: {
    getCourseSrc() {
      if (!this.$store.state.course) {
        return '暂无课程描述'
      }
      this.courseSrc = this.$store.state.course
    },
    getTeacherInfo() {
      this.$axios
        .post('/api/user/userInfo', {
          teacherId: this.courseSrc.teacherId
        })
        .then(res => {
          this.teacherInfo = res.data.data
        })
    },
    handleComent() {
      this.$axios
        .post('/api/course/comment', {
          courseId: this.courseSrc.id,
          evaluateAvatar: localStorage.getItem('ke_avatar'),
          evaluateNickname: localStorage.getItem('ke_nickName'),
          evaluateContent: this.comment,
          score: this.score
        })
        .then(res => {
          this.reload()
        })
        .catch(err => {
          throw err
        })
    }
  }
}
</script>

<style lang="stylus" scoped>
.ke-course-teacher-info {
  overflow: hidden;

  .teacher-info {
    width: 100%;
    height: 80px;
    box-sizing: border-box;
    padding: 10px 10px 10px 90px;
    position: relative;
    overflow: hidden;

    .avatar {
      position: absolute;
      left: 20px;
      height: 10px;
      width: 60px;
      height: 60px;

      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }

    .name {
      margin: 8px 0;
      color: rgb(35, 184, 255);
    }

    .personalized {
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      font-size: 14px;
    }
  }

  .course-desc {
    box-sizing: border-box;
    padding: 5px 10px 5px 20px;

    .title {
      font-size: 16px;
      margin-bottom: 5px;
    }

    .desc {
      text-indent: 2em;
      font-size: 14px;
      line-height: 18px;
      height: 90px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 5; // 行数
      -webkit-box-orient: vertical;
    }
  }

  .comment {
    box-sizing: border-box;
    padding: 10px 10px 5px 20px;
    border-top: 1px solid #ffffff;
    margin-top: 10px;
  }
}
</style>
